package com.lebang.controller.sys;

import com.lebang.aop.ConfigRecord;
import com.lebang.common.Login;
import com.lebang.domain.AppRousePlan;
import com.lebang.service.earn.AppRousePlanService;
import com.lebangweb.common.UUIDUtil;
import com.lebangweb.response.Callback;
import com.lebangweb.response.JsonData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.time.LocalDateTime;


/**
 * 用户签到数据更改
 *
 * @author hwq
 * @date 2020-03-25
 */
@Controller
@RequestMapping("/sys/approuseplan")
public class AppRousePlanController {
    @Autowired
    private AppRousePlanService baseService;

    @GetMapping("/list")
    public String list() {
        return "/approuseplan/list";
    }

    @GetMapping("/add")
    public String add(Integer id, Model model) {
        AppRousePlan vo;
        if (id != null) {
            vo = baseService.selectById(id);
        } else {
            vo = new AppRousePlan();
        }
        model.addAttribute("item", vo);
        return "/approuseplan/edit";
    }


    @PostMapping("/edit")
    @ResponseBody
    @ConfigRecord
    public JsonData edit(AppRousePlan vo) {
        if (vo.getId() != null) {
            vo.setModifyTime(LocalDateTime.now());
            baseService.updateById(vo);
        } else {
            vo.setCreateTime(LocalDateTime.now());
            vo.setHasDeleted(0);
            vo.setPlanKey(UUIDUtil.S());
            baseService.insertModel(vo);
        }

        return Callback.success("success", "修改成功");
    }

    @Login
    @PostMapping("/delete")
    @ResponseBody
    public JsonData delete(Integer id) {
        baseService.deleteById(id);
        return Callback.success("success", "删除成功");
    }

}
